using System;
using System.Windows.Forms;
using Jbe.TestSuite.Infrastructure.Interface;
using Microsoft.Practices.CompositeUI;
using Microsoft.Practices.CompositeUI.Commands;
using Jbe.TestSuite.TestDevice.FunctionGen.Driver.Constants;
using Jbe.TestSuite.TestDevice.FunctionGen.Driver.Services;
using Jbe.TestSuite.TestDevice.Manager.Interface.Services;
using Jbe.TestSuite.Infrastructure.Interface.Services;

namespace Jbe.TestSuite.TestDevice.FunctionGen.Driver
{
    public class ModuleController : WorkItemController
    {
        private IUIElementCreationService uiElementCreationService;

        [ServiceDependency]
        public IUIElementCreationService UIElementCreationService
        {
            set { uiElementCreationService = value; }
        }

        public override void Run()
        {
            IMenuItem newFunctionGen = uiElementCreationService.CreateMenuItem("Function Generator");
            WorkItem.UIExtensionSites[UIExtensionSiteNames.NewDevice].Add(newFunctionGen);
            newFunctionGen.Click += new EventHandler(NewFunctionGenClick);
        }

        #region Command and Event handler

        private void NewFunctionGenClick(object sender, EventArgs e)
        {
            ControlledWorkItem<InstanceController> instanceWorkItem = WorkItem.WorkItems.AddNew<ControlledWorkItem<InstanceController>>();
            instanceWorkItem.Controller.Run();
        }

        #endregion
    }
}
